ACLOCAL_AMFLAGS = -I m4

AM_CFLAGS = $(ICU_CFLAGS) -std=c99 -pedantic -Wall
AM_LDFLAGS = -lpthread -L$(ERLANG_LIB_DIR_erl_interface)/lib -lerl_interface -lei $(ICU_LIBS) $(ICU_IOLIBS)

DRYVERLDATA = src/starling_drv.xml
DRYVERLSRC = gen/starling_drv.c gen/starling_drv.h

bindir = $(ERLANG_INSTALL_LIB_DIR_starling)/priv/bin
bin_PROGRAMS = starling_drv
starling_drv_SOURCES = c_src/decode_encode.c \
	c_src/driver.c \
	c_src/myicu.c \
	c_src/myicu.h \
	c_src/read_write.c \
	c_src/starling.h

pkglibdir = $(ERLANG_INSTALL_LIB_DIR_starling)/priv/lib
pkglib_LTLIBRARIES = starling_drv.la
nodist_starling_drv_la_SOURCES = $(DRYVERLSRC)
starling_drv_la_SOURCES = c_src/starling_drv_util.h c_src/starling_drv_util.c
starling_drv_la_LDFLAGS = -module $(AM_LDFLAGS)
starling_drv_la_CFLAGS = -I. -I$(srcdir)/c_src -I$(ERLANG_ERTS_DIR)/include -I$(ERLANG_LIB_DIR_erl_interface)/include $(ICU_CFLAGS) $(AM_CFLAGS)
CLEANFILES = $(nodist_starling_drv_la_SOURCES)

erlsrcdir = $(ERLANG_INSTALL_LIB_DIR_starling)/src
nodist_erlsrc_DATA = gen/starling_drv.erl \
	gen/starling_drv_gen_server.erl
dist_erlsrc_DATA = src/starling_drv_test.erl \
	src/starling_app.erl \
	src/starling_server.erl \
	src/starling_sup.erl \
	src/ustring.erl
CLEANFILES += $(nodist_erlsrc_DATA)

erlbeamdir = $(ERLANG_INSTALL_LIB_DIR_starling)/ebin
erlbeam_SCRIPTS = ebin/starling_app.app
erlbeam_DATA = ebin/starling_drv.beam \
	ebin/starling_drv_gen_server.beam \
	ebin/starling_drv_test.beam \
	ebin/starling_app.beam \
	ebin/starling_server.beam \
	ebin/starling_sup.beam \
	ebin/ustring.beam
CLEANFILES += $(erlbeam_DATA)

EXTRADIST = $(DRYVERLDATA)

gen/starling_drv.h: gen/starling_drv.c
gen/starling_drv.erl: gen/starling_drv.c
gen/starling_drv_gen_server.erl: gen/starling_drv.c
gen/starling_drv.c: src/starling_drv.xml c_src/starling_drv_util.c
	(mkdir -p gen ; cd gen ; $(DRYVERL) ../src/starling_drv.xml)

ebin/%.beam: src/%.erl
	$(ERLC) $(ERLCFLAGS) -o ebin -DSTARLING_DRIVER_DIR=\"$(pkglibdir)\" -b beam $<

ebin/%.beam: gen/%.erl
	$(ERLC) $(ERLCFLAGS) -o ebin -b beam $<

clean-local:
	rm -rf gen
